//****************************************************
// Porman Project 2
// Filename: CShaderObject.h
// Date: 2008/01/13
// Author: KengYu Lin
// Modify:
//****************************************************
#ifndef _CSHADEROBJECT_H
#define _CSHADEROBJECT_H
#include <vector>
#include "CBaseObject.h"

namespace Porman
{

namespace GL
{

class CTextureBaseObject;
class CSamplerState;

class CShaderObject : public CBaseObject
{
    friend class CRenderDevice;
public:
    PGL_API EShaderType Type( void ) { return m_eType; }
    PGL_API virtual void setName( const char* pName ) { m_sName = std::string("ShaObj_") + std::string( pName ); }
    PGL_API bool isCompiled( void );
    PGL_API std::string getCode( EShaderCodeType enumCodeType );

    PGL_API ERESULT setArraySize( const HSHADERPARAM* pParam, const int& iSize );
    PGL_API ERESULT setArrayMultiDimSize( const HSHADERPARAM* pParam, const int* pSize );
    PGL_API ERESULT setParameterFloat( const HSHADERPARAM* pParam, float fVal );
    PGL_API ERESULT setParameterFloatArrayRow( const HSHADERPARAM* pParam, unsigned int iNumElement, const float* fArray );
    PGL_API ERESULT setParameterFloatArrayCol( const HSHADERPARAM* pParam, unsigned int iNumElement, const float* fArray );
    PGL_API ERESULT setSampler( const HSHADERPARAM* pParam, const CSamplerState* pSampler, CTextureBaseObject* pTextureObj );
    PGL_API ERESULT setInterface( HSHADERPARAM* pInterface, const HSHADERPARAM* pParam );

    PGL_API ERESULT setArraySize( const char* sParam, const int& iSize );
    PGL_API ERESULT setArrayMultiDimSize( const char* sParam, const int* pSize );
    PGL_API ERESULT setParameterFloat( const char* sParam, float fVal );
    PGL_API ERESULT setParameterFloatArrayRow( const char* sParam, unsigned int iNumElement, const float* fArray );
    PGL_API ERESULT setParameterFloatArrayCol( const char* sParam, unsigned int iNumElement, const float* fArray );
    PGL_API ERESULT setSampler( const char* sParam, const CSamplerState* pSampler, CTextureBaseObject* pTextureObj );
    PGL_API ERESULT setInterface( const char* sInterface, const HSHADERPARAM* pParam );

    PGL_API ERESULT getParameter( const char* sParam, HSHADERPARAM* pParam );
    PGL_API ERESULT getArrayDim( const char* sParam, int& iDim );
    PGL_API ERESULT getArrayDim( HSHADERPARAM* pParam, int& iDim );
    PGL_API ERESULT getArraySize( const char* sParam, int iDim,int& iSize );
    PGL_API ERESULT getArraySize( HSHADERPARAM* pParam, int iDim,int& iSize );
    PGL_API ERESULT getInstance( const char* sInstance, HSHADERPARAM* pParam );
    PGL_API ERESULT getInstanceArray( const char* sInstance, int iLength, HSHADERPARAM* pParam );
    PGL_API ERESULT getInstanceMultiDimArray( const char* sInstance, int iDim, const int* pLength, HSHADERPARAM* pParam );
    PGL_API ERESULT getInstanceParam( const char* sInstance, const HSHADERPARAM* pInParam, HSHADERPARAM* pOutParam );

protected:
    CShaderObject( CRenderDevice* pDevice, EShaderType enumType );
    virtual ~CShaderObject( void );
    void _disableAllSamplerParameters( void );
    void _clearParam( void );
    void _enableVaryingShaderParameters( void );
    void _disableVaryingShaderParameters( void );
    int _getSemanticSize( void );
    SSemantic* _getSemantic( int iIndex );

protected:
    EShaderType    m_eType;
    CGprogram      m_cgProgram;
    std::string    m_sFileName;
    std::vector<HSHADERPARAM> m_vectSamplerParams;
    std::vector<CGparameter> m_vectInstParams;
    std::vector<SSemantic> m_vectSemantic;
};

}//End namespace GL

}//End namespace Porman

#endif